package com.yangrui.app.controller;

import com.yangrui.app.entity.VideoOrder;
import com.yangrui.app.service.VideoOrderService;
import com.yangrui.app.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/video-order")
@Api(value = "视频订单接口", tags = "视频订单接口")
public class VideoOrderController {

    @Autowired
    private VideoOrderService videoOrderService;

    // 下单
    @PostMapping("/insert")
    @ApiOperation(value = "下单", notes = "")
    public Result insert(@ApiParam(value = "用户id", required = true) @RequestParam("user-id") Integer userId,
                            @ApiParam(value = "视频id", required = true) @RequestParam("video-id") Integer videoId) {
        int result = videoOrderService.insert(userId, videoId);
        return result > 0 ? Result.ok(result): Result.fail();
    }

    // 查询订单
    @GetMapping("/select-by-user-id")
    @ApiOperation(value = "查询订单", notes = "")
    public Result selectByUserId(@ApiParam(value = "用户id", required = true) @RequestParam("user-id") Integer userId) {
        List<VideoOrder> list = videoOrderService.selectByUserId(userId);
        return list!=null? Result.ok(list):Result.fail();
    }

}
